package com.captain.special.哈希表;

import java.util.HashMap;
import java.util.Map;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/4/4 15:45
 */
public class 赎金信383 {

    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> map = new HashMap<>();

        char[] mChars = magazine.toCharArray();
        for (char mChar : mChars) {
            map.put(mChar, map.getOrDefault(mChar, 0) + 1);
        }
        char[] aChar = ransomNote.toCharArray();
        for (char c : aChar) {
            Integer val = map.get(c);
            if (val == null) return false;
            val = val - 1;
            if (val < 0) {
                return false;
            }
            map.put(c,val);
        }
        return true;

    }
}
